using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;

public class PlayerCtrl : MonoBehaviour
{
    private Rigidbody2D m_Rb2D;
    [SerializeField]
    private float m_JumpForce = 8;
    [SerializeField]
    private float m_LaunchForce = 8;
    [SerializeField]
    private float m_GScl = 8;
    private void Awake()
    {
        m_Rb2D = GetComponent<Rigidbody2D>();
        m_GScl = m_Rb2D.gravityScale;
    }

    private void Update()
    {

        //JetPack();
        //Jump();
        ReversG();
    }
    private void Jump()
    {
        if (Input.anyKeyDown)
        {
            m_Rb2D.bodyType = RigidbodyType2D.Static;
            m_Rb2D.bodyType = RigidbodyType2D.Dynamic;
            m_Rb2D.AddForce(Vector2.up * m_JumpForce, ForceMode2D.Impulse);
        }
    }

    private void JetPack()
    {
        if (Input.anyKeyDown)
        {
            m_Rb2D.bodyType = RigidbodyType2D.Static;
            m_Rb2D.bodyType = RigidbodyType2D.Dynamic;
        }

        if (Input.anyKey)
        {
            m_Rb2D.AddForce(Vector2.up * m_LaunchForce, ForceMode2D.Force);

        }
    }

    private void ReversG()
    {
        if (Input.anyKeyDown)
        {
            //m_Rb2D.bodyType = RigidbodyType2D.Static;
            //m_Rb2D.bodyType = RigidbodyType2D.Dynamic;
            m_GScl = -m_GScl;
            m_Rb2D.gravityScale = m_GScl;
        }

    }

    public void Rush()
    {
        m_Rb2D.bodyType = RigidbodyType2D.Static;
        m_Rb2D.bodyType = RigidbodyType2D.Dynamic;
        m_Rb2D.DOMoveX(m_Rb2D.position.x + 0.5f, 0.2f);
    }
}
